﻿

namespace LxCFD
{
    public class ConnectWallBase : ConnectBase
    {

        protected Value1Base<double> O_Gamma;
        protected Value1Base<double> N_Gamma;

        protected ValueBase<double> S;//面源，！！！！

        protected void setArray_2(ValueBase<double> S, EquationBase OMatrix, EquationBase NMatrix)
        {
            SetArray(OMatrix, NMatrix);
            this.O_Gamma = getGamma(O_Matrix);
            this.N_Gamma = getGamma(N_Matrix);

            this.S = S;
        }
        private Value1Base<double> getGamma(EquationBase m)
        {
            if (m is PossionEquationBase possion)
            {
                return possion.Gamma;
            }
            else if (m is NSEquationBase ns)
            {
                return ns.Gamma;
            }
            else
            {
                LxConsole.Error(string.Format("无法获取公式中Gamma值"));
                return null;
            }
        }
        protected void setAb_ONALU(ref PairMatrix ab, int ofid, int nfid)
        {
            O_ALUN[ofid] = -ab.a11;
            O_ALUO[ofid] = 1;
            O_bFaceCommon[ofid] = ab.b1;
            N_ALUN[nfid] = -ab.a44;
            N_ALUO[nfid] = 1;
            N_bFaceCommon[nfid] = ab.b4;
        }
    }
}
//public virtual void SetAb_Step2(int taskIndex)
//{
//    throw new NotImplementedException();
//}
//public virtual void Relax(int taskIndex)
//{
//    throw new NotImplementedException();
//}
//public virtual void CalByGS(int taskIndex)
//{
//    throw new NotImplementedException();
//}

//public virtual void CalByJacobi_Step1(int taskIndex)
//{
//    throw new NotImplementedException();
//}

//public virtual void CalByJacobi_Step2(int taskIndex)
//{
//    throw new NotImplementedException();
//}
//public virtual void SendRestrict_ALUr(out double A_Diag, out double OZone_A_LU_O, out double OZone_A_LU_N, out double NZone_A_LU_O, out double NZone_A_LU_N, ref MGMesh.Pair CoarsePair)
//{
//    throw new NotImplementedException();
//}

//public virtual void SendRestrict_r(ref MGMesh.Pair CoarsePair)
//{
//    throw new NotImplementedException();
//}
//public void ReceiveProlong(ref MGMesh.Pair CoarsePair, double e)
//{
//    foreach (var fpid in CoarsePair.FinePairs)
//    {
//        ref Mesh.Pair pair = ref Pairs[fpid];
//        O_x[pair.O_Cell] += e;
//        N_x[pair.N_Cell] += e;
//    }
//}

//protected void CopyFaceAb(int taskIndex)
//{
//    if (O_ALUO != null)
//    {
//        O_Index.FaceIdx.GetSeg(out int i1, out int endp1, taskIndex);
//        for (; i1 < endp1; i1++)
//        {
//            O_ALUO[i1] = O_ALUN[i1];
//        }
//    }
//    if (N_ALUO != null)
//    {
//        N_Index.FaceIdx.GetSeg(out int i1, out int endp1, taskIndex);
//        for (; i1 < endp1; i1++)
//        {
//            N_ALUO[i1] = N_ALUN[i1];
//        }
//    }
//}

//private void getScalarInf(out MatrixBase_Ab scalar, out double[] ALU, out double[] ALU_OtherSide, out Value1Base Gamma, FieldsBase_InZone field)
//{
//    if (field is FieldsInSolid finsolid)
//    {
//        scalar = finsolid.T;
//        ALU = finsolid.T.A_LU_Diff;
//        ALU_OtherSide = null;
//        Gamma = finsolid.T.Gamma;
//    }
//    else if (field is FieldsInLaminarFlow finflow)
//    {
//        scalar = finflow.T;
//        ALU = finflow.T.ALUN;
//        ALU_OtherSide = finflow.T.ALUO;
//        Gamma = finflow.T.Gamma;
//    }
//    else
//    {
//        scalar = null;
//        ALU = null;
//        ALU_OtherSide = null;
//        Gamma = null;
//        LxConsole.AddLine(LogTypes.错误, string.Format($"连接:{contact.name}出现错误，未识别的标量场类型"));
//    }
//}
//public void pass_xOre_ToCoarser(out double[] e_ownerfine, out double[] e_neighborfine)
//{
//    e_ownerfine = this.O_x;
//    e_neighborfine = this.N_x;
//}
//public void Pass_ALU_ToCoarser(out double A_LU_O, out double A_LU_N, ref MGMesh.Face CoarseFace)
//{
//    double aluo = 0, alun = 0;
//    foreach (int f in CoarseFace.FineFaces_O2N)
//    {
//        aluo += this.BetZone_A_LU_O[f];
//        alun += this.BetZone_A_LU_N[f];
//    }
//    A_LU_O = aluo;
//    A_LU_N = alun;
//}
//protected void calContact(double[] OArray, double[] NArray, int taskIndex)
//{
//    {
//        O_Index.CellIdx.GetSeg(out int i1, out int endp1, taskIndex);
//        for (; i1 < endp1; i1++)
//        {
//            double aluproduct = 0;
//            foreach (var f in O_cells[i1].CellFacesAsO)
//            {
//                aluproduct += BetZone_A_LU_O[f] * NArray[Pairs[f].NeighborCellIndex];
//            }
//            OArray[i1] = aluproduct;
//        }
//    }
//    {
//        O_Index.CellIdx.GetSeg(out int i1, out int endp1, taskIndex);
//        for (; i1 < endp1; i1++)
//        {
//            double aluproduct = 0;
//            foreach (var f in N_cells[i1].CellFacesAsO)
//            {
//                aluproduct += BetZone_A_LU_N[f] * OArray[Pairs[f].OwnerCellIndex];
//            }
//            NArray[i1] = aluproduct;
//        }
//    }
//}
//public double[] Local_A_LU_O;
//public double[] Local_A_LU_N;
//public double[] BetZone_A_LU_O;
//public double[] BetZone_A_LU_N;
//if (Local_A_LU_O == null)
//{
//    Local_A_LU_O = new double[O_Index.FaceIdx.GetCount()];
//}
//if (Local_A_LU_N == null)
//{
//    Local_A_LU_N = new double[O_Index.FaceIdx.GetCount()];
//}
//protected void CopyFaceAb(int taskIndex)
//{
//    if (O_A_LU_O != null)
//    {
//        O_Index.FaceIdx.GetSeg(out int i1, out int endp1, taskIndex);
//        for (; i1 < endp1; i1++)
//        {
//            O_A_LU_O[i1] = O_A_LU_N[i1];
//        }
//    }
//    if (N_A_LU_O != null)
//    {
//        N_Index.FaceIdx.GetSeg(out int i1, out int endp1, taskIndex);
//        for (; i1 < endp1; i1++)
//        {
//            N_A_LU_O[i1] = N_A_LU_N[i1];
//        }
//    }

//}
//public void pass_A_r_owner_ToCoarser(out double A_owner, ref MGMesh.Cell ownerCoarser)
//{
//    double Atemp = 0;
//    double rtemp = 0;
//    foreach (int ocell in ownerCoarser.FineCells)
//    {
//        int oface = O_cells[ocell].CellFacesAsN[0];
//        int nface = oface + NFaceBaseO;
//        int ncell = ocell + NCellBaseO;
//        double xo = O_x[ocell];
//        double xn = N_x[ncell];

//        double atemp = O_A_Diag[ocell];
//        Atemp += atemp;
//        rtemp += O_b[ocell]
//            - O_A_LU_N[oface] * O_x[O_faces[oface].OwnerCellIndex]
//            - atemp * xo;

//        atemp = N_A_Diag[ncell];
//        Atemp += atemp;
//        rtemp += N_b[ncell]
//            - N_A_LU_N[nface] * N_x[N_faces[nface].OwnerCellIndex]
//            - atemp * xn;
//        rtemp -= A_LU_Diff[oface + IFaceBaseO] * (xo + xn);
//    }
//    A_owner = Atemp;
//    ownerCoarser.r = rtemp;
//}
//void IPassDataToCoarserContact.pass_r_owner_ToCoarser(ref MGMesh.Cell ownerCoarser)
//{
//    double rtemp = 0;
//    foreach (int ocell in ownerCoarser.FineCells)
//    {
//        int oface = O_cells[ocell].CellFacesAsN[0];
//        int nface = oface + NFaceBaseO;
//        int ncell = ocell + NCellBaseO;
//        double xo = O_x[ocell];
//        double xn = N_x[ncell];

//        double atemp = O_A_Diag[ocell];
//        rtemp += O_b[ocell]
//            - O_A_LU_N[oface] * O_x[O_faces[oface].OwnerCellIndex]
//            - atemp * xo;

//        atemp = N_A_Diag[ncell];
//        rtemp += N_b[ncell]
//            - N_A_LU_N[nface] * N_x[N_faces[nface].OwnerCellIndex]
//            - atemp * xn;
//        rtemp -= A_LU_Diff[oface + IFaceBaseO] * (xo + xn);
//    }
//    ownerCoarser.r = rtemp;
//}
//public void pass_A_LU_owner_ToCoarser(out double A_lu_owner, ref CoarseFace ownerCoarser)
//{
//    double aluo = 0;
//    foreach (int fineface in ownerCoarser.FineFaces_O2N)
//    {
//        aluo += O_A_LU[fineface];
//    }
//    A_lu_owner = aluo;
//}

//public void pass_A_LU_neighbor_ToCoarser(out double A_lu_neighbor, ref CoarseFace neighborCoarser)
//{
//    double alu = 0;
//    foreach (int fineface in neighborCoarser.FineFaces_O2N)
//    {
//        alu += N_A_LU[fineface];
//    }
//    A_lu_neighbor = alu;
//}